using System;
using Unity.VisualScripting;
using UnityGameFramework.Runtime;

namespace LS.UGFUnits
{
    public class ShowEntity : EntityUnit
    {
        [Serialize]
        [Inspectable, UnitHeaderInspectable]
        [TypeFilter(typeof(EntityLogic))]
        public System.Type EntityLogicType { get; private set; }
        
        [DoNotSerialize]
        public ValueInput SerialId { get; set; }
        
        [DoNotSerialize]
        public ValueInput AssetName { get; set; }
        
        [DoNotSerialize]
        public ValueInput GroupName { get; set; }
        
        [DoNotSerialize]
        public ValueInput Priority { get; set; }

        [DoNotSerialize]
        [NullMeansSelf]
        public ValueInput UserData { get; set; }
        protected override void Definition()
        {
            base.Definition();
            SerialId = ValueInput<int>(nameof(SerialId));
            AssetName = ValueInput<string>(nameof(AssetName), string.Empty);
            GroupName = ValueInput<string>(nameof(GroupName), string.Empty);
            Priority = ValueInput<int>(nameof(Priority), 0);
            UserData = ValueInput<object>(nameof(UserData), null);
            Requirement(SerialId, Input);
            Requirement(AssetName, Input);
            Requirement(GroupName, Input);
            Requirement(Priority, Input);
            Requirement(UserData, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            Type type = EntityLogicType;
            int serialId = flow.GetValue<int>(SerialId);
            string assetName = flow.GetValue<string>(AssetName);
            string groupName = flow.GetValue<string>(GroupName);
            int priority = flow.GetValue<int>(Priority);
            object userData = flow.GetValue<object>(UserData);
            Target?.ShowEntity(serialId, type, assetName, groupName, priority, userData);
            return base.In(flow);
        }
    }
}